<template>
  <view class="type_choose_wrap">
    <view
      class="type_choose_item"
      v-for="item in menus"
      :key="item.catId"
      @click="handleClick(item)"
    >
      <view class="item_img">
        <image mode="widthFix" :src="handleImgurl(item)" />
      </view>
      <view class="item_title">{{ item.name }}</view>
      <view class="item_english"></view>
    </view>
  </view>
</template>

<script>
export default {
  methods: {
    async getMenus() {
      let res = []
      try {
        res = await this.request({ url: '/exercise/category/list/tree' })
        this.menus = res.data
      } catch (error) {
        console.log(error.message)
      }
    },
    handleClick(item) {
      this.$emit('enterCategory', item)
    },
  },
  data() {
    return {
      menus: [],
    }
  },
  mounted() {
    this.getMenus()
  },
  computed: {
    handleImgurl() {
      return (item) => {
        switch (item.catId) {
          case 1:
            return require('@/static/img/computer.svg')
          case 2:
            return require('@/static/img/math.svg')
          default:
            return require('@/static/img/computer.svg')
        }
      }
    },
  },
}
</script>

<style lang="scss">
.type_choose_wrap {
  display: flex;
  flex-wrap: wrap;
  padding: 30rpx;
  .type_choose_item {
    width: 30%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: #f6b923;
    border-radius: 10rpx;
    padding: 20rpx;
    box-shadow: #ccc 1px 1px 10px;
    &:nth-child(n + 2) {
      margin-left: 34rpx;
    }
    &:nth-child(2) {
      background: #80d256;
    }
    &:nth-child(3) {
      background: #01b9df;
    }
    .item_img {
      image {
        width: 130rpx;
      }
    }
    .item_title {
      font-size: 30rpx;
      color: #fff;
    }
    .item_english {
      font-size: 30rpx;
      color: #fff;
      background: transparent;
    }
  }
}
</style>